﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;

namespace Se7en.Admin.Business
{
    public static partial class AccountingBLL
    {
        //private readonly string _sportingSolutionsUrl;
        //private const string LoginResource = @"/Login";
        //private const string TokenResource = @"/{0}/Token";
        //private const string ContentType = "text/xml";
        //private const string AuthenticationTokenHeader = "X-Authentication-Token";
        //private const string LoginPostData = @"<LoginRequest><UserName>{0}</UserName>\<Password>{1}</Password></LoginRequest>";
        ///// <summary>
        ///// Creates a new UserResourceExample using the URL provided:
        ///// </summary>
        ///// <param name="url">Obtain URL from {account_manager}@sportingsolutions.com</param>
        ///// </summary>
        //public TipFreeBLL(string url)
        //{
        //    _sportingSolutionsUrl = url;
        //}

        ///// <summary>
        ///// Logs in to the API and returns a Session ID:
        ///// </summary>
        ///// <param name=”username”>Obtain username from {account_manager}@sportingsolutions.com</param>
        ///// <param name=”password”>Obtain password from {account_manager}@sportingsolutions.com</param>
        ///// <returns></returns>

        //public Guid Login(string username, string password)
        //{
        //    string loginUrl = _sportingSolutionsUrl + LoginResource;
        //    // Set up the HTTP request:
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginUrl);
        //    string postData = string.Format(LoginPostData, username, password);
        //    byte[] postBytes = Encoding.ASCII.GetBytes(postData);
        //    request.Method = "POST";
        //    request.ContentType = ContentType;
        //    request.ContentLength = postBytes.Length;
        //    Stream requestStream = request.GetRequestStream();
        //    requestStream.Write(postBytes, 0, postBytes.Length);
        //    requestStream.Close();
        //    // Get the HTTP response and process the Session Token from it:
        //    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        //    XmlDocument xmlDocument = new XmlDocument();
        //    xmlDocument.Load(response.GetResponseStream());
        //    XmlNodeList nodes = xmlDocument.GetElementsByTagName("Token");
        //    string token = nodes[0].InnerText;
        //    return new Guid(token);
        //}
        ///// <summary>
        ///// Logs out of the API:
        ///// </summary>
        ///// <param name=”username”>Obtain username from {account_manager}@sportingsolutions.com</param>
        ///// <param name=”sessionToken”>Obtain session token from Login Method</param>

        //public void Logout(string username, Guid sessionToken)
        //{
        //    string tokenUrl = _sportingSolutionsUrl + string.Format(TokenResource, username);
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(tokenUrl);
        //    request.Method = "DELETE";
        //    request.Headers.Add(AuthenticationTokenHeader, sessionToken.ToString());
        //    request.GetResponse();
        //}

        ///// <summary>
        ///// Gets the User Profile for the specified User (requires a valid session token):
        ///// </summary>
        ///// <param name=”username”>Obtain username from {account_manager}@sportingsolutions.com</param>
        ///// <param name=”sessionToken”>Obtain session token from Login Method</param>
        ///// <returns></returns>

        //public XmlDocument GetUserProfile(string username, Guid sessionToken)
        //{
        //    string tokenUrl = _sportingSolutionsUrl + string.Format(TokenResource, username);
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(tokenUrl);
        //    request.Method = "GET";
        //    request.Headers.Add("X-Authentication-Token", sessionToken.ToString());
        //    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        //    XmlDocument xmlDocument = new XmlDocument();
        //    xmlDocument.Load(response.GetResponseStream());
        //    return xmlDocument;
        //}
    }
}
